package com.simpleframe.core.io;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class AbstractResource implements Resource{
	
	public boolean exists()  {
		try {
			return getFile().exists();
		}catch (Exception ex) {
			//  Fall back to stream existence: can we open the stream?
			try {
				InputStream is = getInputStream();
				is.close();
				return true;
			}
			catch (Throwable isEx) {
				return false;
			}
		}
	}

	public File getFile() throws IOException {
		throw new FileNotFoundException(" cannot be resolved to absolute file path");
	}

	public String getFilename() {
		throw new IllegalStateException(" does not carry a filename");
	}

	public boolean isOpen() {
		return false;
	}

	public boolean isReadable() {
		return true;
	}

	public long lastModified() throws IOException {
		long lastModified = getFile().lastModified();
		if (lastModified == 0L) {
			throw new FileNotFoundException(
					" cannot be resolved in the file system for resolving its last-modified timestamp");
		}
		return lastModified;
	}

	public InputStream getInputStream() throws IOException {
		// TODO 返回 InputStream
		return null;
	}

	
	public URL getURL() throws IOException {
		throw new FileNotFoundException(" cannot be resolved to URL");
	}

}
